package com.dingreading.cloud.admin.service.impl;

import com.dingreading.cloud.admin.entity.table.CmactivationCodeTypeTableDef;
import com.dingreading.cloud.common.base.R;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.dingreading.cloud.admin.entity.CmactivationCodeType;
import com.dingreading.cloud.admin.mapper.CmactivationCodeTypeMapper;
import com.dingreading.cloud.admin.service.CmactivationCodeTypeService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * 激活码类型表 服务层实现。
 *
 * @author EDY
 * @since 2025-10-28
 */
@Service
public class CmactivationCodeTypeServiceImpl extends BaseServiceImpl<CmactivationCodeTypeMapper, CmactivationCodeType, CmactivationCodeTypeTableDef> implements CmactivationCodeTypeService {

    @Override
    protected CmactivationCodeTypeTableDef getTable() {
        return CmactivationCodeTypeTableDef.cmactivationCodeType;
    }

    @Override
    public R<Object> getList(String headStaffUid, String headStaffName) {
        if (StringUtils.isBlank(headStaffUid) || StringUtils.isBlank(headStaffName))
            return R.fail("员工字段缺少请检查！");
        QueryWrapper query = QueryWrapper.create()
                .where(table.enabled.eq(1))
                .orderBy(table.id.desc());
        return R.ok(getMapper().selectListByQuery(query));
    }

    @Override
    public CmactivationCodeType getByUid(String activationTypeUid) {

        return getMapper().selectOneByCondition(table.uid.eq(activationTypeUid));
    }
}
